from docx import Document
import os


def transform_docx_to_txt(target_file_path, result_file_path):

	if not target_file_path.endswith(".docx") and not target_file_path.endswith(".doc"):
		raise Exception("无效格式的文件") 

	if os.path.exists(result_file_path) == False:
			os.mknod(result_file_path)

	document = Document(target_file_path)  
	
	with open(result_file_path,'w') as file:
		for paragraph in document.paragraphs:
			file.write(paragraph.text + "\n")
		file.close()

if __name__ == "__main__":
	transform_docx_to_txt("..//material//SSE-script.docx", "..//output//docx_output.txt")